import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import javadsd from '@dfeidao/atom-web/msg/javadsd';
import tree from '@dfeidao/fd-w000001';
// import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import { refsystemid } from './config';

// import whoami from '@dfeidao/atom-web/msg/whoami';
import render from '@dfeidao/atom-web/render/render';
import P05 from './P05';
interface B {
	docDataStore: {
		master: {
			dataArray: [{
				no: string
				formid: string;
				grid_1: {
					dataArray: [
						{
							no: string;
							formid: string;
							formname: string;
							action_name: string;
							action_keyword: string;
						}
					]
				}
			}]
		};
	};
}
export default async function a008(fd: IFeidaoAiBrowserComponent) {
	// const userinf = await whoami();
	// const productid1 = userinf.productid;
	const productid1 = get(fd, 'productid') as string;

	const select1 = fd.data.node.querySelector<HTMLSelectElement>('[select]');
	const index = select1.options.selectedIndex;
	const client_type1 = select1.options[index].value;
	const condition = {
		param: {
			productid: productid1,
			client_type: client_type1
		}
	};
	set(fd, 'client_type', client_type1);
	const ret = await javadsd('12', '12', 'smart_securitydsd0000001', condition) as B;
	const array = new Array();
	ret.docDataStore.master.dataArray.forEach((i, idex) => {
		if (i.grid_1.dataArray.length > 0) {
			i.grid_1.dataArray.forEach((j) => {
				j.no = j.formid;
				j.formid = j.formid + j.action_keyword;
				j.formname = j.action_name;
				array.push(j);
			});
		}
		delete i.grid_1;
		i.no = '';
		if (!i.formid) {
			i.formid = JSON.stringify(idex);
		}
		array.push(i);
	});
	render(fd, JSON.stringify(array), P05, 'P05', 'inner');

	const tenantid = get(fd, 'tenantid') as string;
	if (tenantid) {
		const condition2 = {
			param: {
				productid: tenantid,
				client_type: client_type1
			}
		};
		const ret1 = await javadsd('12', '12', 'smart_securitydsd0000001', condition2) as B;
		const array1 = new Array();
		ret1.docDataStore.master.dataArray.forEach((i) => {
			if (i.grid_1.dataArray.length > 0) {
				i.grid_1.dataArray.forEach((j) => {
					j.no = j.formid;
					j.formid = j.formid + j.action_keyword;
					j.formname = j.action_name;
					array1.push(j.formid);
				});
			}
			delete i.grid_1;
			i.no = '';
			// if (!i.formid) {
			// 	i.formid = JSON.stringify(idex);
			// }
			array1.push(i.formid);
		});
		const zds = fd.data.node.querySelector('[zds]') as tree;
		zds.uncheck_all();
		zds.check_node(array1);
	}
}
